﻿
@using Nop.Services.Stores
@model CustomerModel

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

<script>
    $(document).ready(function () {
        bindBootstrapTabSelectEvent('customer-edit');
    });
</script>

<div class="content">
    <div class="form-horizontal">
        <div id="customer-edit" class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                @Html.RenderBootstrapTabHeader("tab-info", @T("用户信息"), true)
                @if (Model.Id > 0)
                {
                    @Html.RenderBootstrapTabHeader("tab-activitylog", @T("Admin.Customers.Customers.ActivityLog"))
                    @Html.RenderBootstrapTabHeader("tab-hours", @T("月度工时"))
                }
            </ul>
            <div class="tab-content">
                @Html.RenderBootstrapTabContent("tab-info", @TabInfo(), true)
                @if (Model.Id > 0)
                {
                    @Html.RenderBootstrapTabContent("tab-activitylog", @TabActivityLog())
                    @Html.RenderBootstrapTabContent("tab-hours", @TabHours())
                }
            </div>
        </div>
    </div>
</div>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "customer-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab name*@
<input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">

@helper TabInfo()
{
    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.Username)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.Username, required: true)
                        @Html.ValidationMessageFor(model => model.Username)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.TrueName)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.TrueName, required: true)
                        @Html.ValidationMessageFor(model => model.TrueName)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.DepartmentId)
                    </div>
                    <div class="col-md-9">
                        @Html.EditorFor(model => model.DepartmentId, new { SelectList = Model.AvailableDepartments })
                        @Html.ValidationMessageFor(model => model.DepartmentId)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.SelectedCustomerRoleIds)
                    </div>
                    <div class="col-md-9">
                        <div class="input-group input-group-required">
                            @Html.EditorFor(model => model.SelectedCustomerRoleIds, new { SelectList = Model.AvailableCustomerRoles })
                            <div class="input-group-btn">
                                @Html.RequiredHint()
                            </div>
                        </div>
                        <script>
                            $(document).ready(function() {
                                var customerRolesIdsInput = $('#@Html.FieldIdFor(model => model.SelectedCustomerRoleIds)').data("kendoMultiSelect");
                                customerRolesIdsInput.setOptions({
                                    customerRolesIdsInput: false
                                });

                                @if (Model.AvailableCustomerRoles.Count == 0)
                                {
                                    <text>
                                        customerRolesIdsInput.setOptions({
                                            enable: false,
                                            placeholder: '@T("Admin.Customers.Customers.Fields.CustomerRoles.NoRoles")'
                                        });
                                        customerRolesIdsInput._placeholder();
                                        customerRolesIdsInput._enable();
                                    </text>
                                }
                            });
                        </script>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.Password)
                    </div>
                    <div class="col-md-9">
                        <div class="input-group">
                            @Html.NopEditorFor(model => model.Password)
                            <div class="input-group-btn">
                                @if (Model.Id > 0)
                                {
                                    <button type="submit" name="changepassword" class="btn btn-info">
                                        @T("Admin.Customers.Customers.Fields.Password.Change")
                                    </button>
                                }
                            </div>
                        </div>
                        @Html.ValidationMessageFor(model => model.Password)
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.TelPhone)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.TelPhone)
                        @Html.ValidationMessageFor(model => model.TelPhone)
                    </div>
                </div>
                @*@if (Model.GenderEnabled)
        {
            <div class="form-group">
                <div class="col-md-3">
                    @Html.NopLabelFor(model => model.Gender)
                </div>
                <div class="col-md-9">
                    <div class="raw">
                        <div class="col-md-1">
                            <div class="radio">
                                <label>
                                    @Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { id = "Gender_Male" })
                                    @T("Admin.Customers.Customers.Fields.Gender.Male")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-11">
                            <div class="radio">
                                <label>
                                    @Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { id = "Gender_Female" })
                                    @T("Admin.Customers.Customers.Fields.Gender.Female")
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        }
        <div class="form-group">
            <div class="col-md-3">
                @Html.NopLabelFor(model => model.DateOfBirth)
            </div>
            <div class="col-md-9">
                @Html.NopEditorFor(model => model.DateOfBirth)
                @Html.ValidationMessageFor(model => model.DateOfBirth)
            </div>
        </div>*@
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.AdminComment)
                    </div>
                    <div class="col-md-9">
                        @Html.NopTextAreaFor(model => model.AdminComment)
                        @Html.ValidationMessageFor(model => model.AdminComment)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.Active)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.Active)
                        @Html.ValidationMessageFor(model => model.Active)
                    </div>
                </div>
                @if (Model.Id > 0)
                {
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.NopLabelFor(model => model.LastIpAddress)
                        </div>
                        <div class="col-md-9">
                            @Html.NopDisplayFor(model => model.LastIpAddress)
                        </div>
                    </div>
                }
                @if (Model.Id > 0)
                {
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.NopLabelFor(model => model.CreatedOn)
                        </div>
                        <div class="col-md-9">
                            @Html.NopDisplayFor(model => model.CreatedOn)
                        </div>
                    </div>
                }
                @if (Model.Id > 0)
                {
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.NopLabelFor(model => model.LastActivityDate)
                        </div>
                        <div class="col-md-9">
                            @Html.NopDisplayFor(model => model.LastActivityDate)
                        </div>
                    </div>
                }
                @if (Model.Id > 0 && !String.IsNullOrEmpty(Model.LastVisitedPage))
                {
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.NopLabelFor(model => model.LastVisitedPage)
                        </div>
                        <div class="col-md-9">
                            @Html.NopDisplayFor(model => model.LastVisitedPage)
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
}
@helper TabActivityLog()
{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <div id="activitylog-grid"></div>

                <script>
                    $(document).ready(function () {
                        $("#activitylog-grid").kendoGrid({
                            dataSource: {
                                type: "json",
                                transport: {
                                    read: {
                                        url: "@Html.Raw(Url.Action("ListActivityLog", "Customer", new { customerId = Model.Id }))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    }
                                },
                                schema: {
                                    data: "Data",
                                    total: "Total",
                                    errors: "Errors"
                                },
                                error: function(e) {
                                    display_kendoui_grid_error(e);
                                    // Cancel the changes
                                    this.cancelChanges();
                                },
                                pageSize: @(defaultGridPageSize),
                                serverPaging: true,
                                serverFiltering: true,
                                serverSorting: true
                            },
                            pageable: {
                                refresh: true,
                                pageSizes: [@(gridPageSizes)],
                                @Html.Partial("_GridPagerMessages")
                            },
                            editable: {
                                confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                mode: "inline"
                            },
                            scrollable: false,
                            columns: [{
                                field: "ActivityLogTypeName",
                                title: "@T("Admin.Customers.Customers.ActivityLog.ActivityLogType")",
                                width: 300,
                            }, {
                                field: "IpAddress",
                                title: "@T("Admin.Customers.Customers.ActivityLog.IpAddress")",
                                width: 100
                            }, {
                                field: "Comment",
                                title: "@T("Admin.Customers.Customers.ActivityLog.Comment")"
                            }, {
                                field: "CreatedOn",
                                title: "@T("Admin.Customers.Customers.ActivityLog.CreatedOn")",
                                width: 200,
                                type: "date",
                                format: "{0:yyyy/MM/dd HH:mm:ss}"
                            }]
                        });
                    });
                </script>
            </div>
        </div>
    </div>
}

@helper TabHours()
{
    @Html.Partial("_CreateOrUpdate.Hours", Model)
}